<?php declare(strict_types=1);


namespace App\Migration;


use Swoft\Db\Schema\Blueprint;
use Swoft\Devtool\Annotation\Mapping\Migration;
use Swoft\Devtool\Migration\Migration as BaseMigration;

/**
 * Class CreateMembers
 *
 * @since 2.0
 *
 * @Migration(time=20191119102413)
 */
class CreateMembersTable extends BaseMigration
{
    private $table = 'members';

    /**
     * @return void
     */
    public function up(): void
    {
//        $sql = <<<SQL
//            CREATE TABLE `bcs_members` (
//              `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
//              `username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户名',
//              `password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码',
//              `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '昵称',
//              `head_icon` varchar(255) NOT NULL DEFAULT '' COMMENT '头像',
//              `create_at` timestamp(0) NULL COMMENT '创建时间',
//              `update_at` timestamp(0) NULL COMMENT '更新时间',
//              `delete_at` timestamp(0) NULL COMMENT '更新时间',
//              PRIMARY KEY (`id`),
//              UNIQUE INDEX `username`(`username`)
//            ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '会员表';
//SQL;
//        $this->execute($sql);
        $this->schema->create($this->table, function (Blueprint $table) {
            $table->charset     ='utf8mb4';
            $table->engine      ='innodb';
            $table->collation   = 'utf8mb4_general_ci';
            $table->comment     = '用户会员表';

            $table->increments('id')->comment('主键');
            $table->string('username', 50)->nullable(false)->default('')->comment('用户名');
            $table->string('password', 255)->nullable(false)->default('')->comment('密码');
            $table->string('nickname', 50)->nullable(false)->default('')->comment('昵称');
            $table->string('head_icon', 255)->nullable(false)->default('')->comment('昵称');

            $table->timestamps(); // 创建时间和删除时间
            $table->softDeletesTz(); // 删除时间
            $table->unique('username');
        });
    }

    /**
     * @return void
     */
    public function down(): void
    {
//        $dropSql = <<<sql
//            drop table if exists `bcs_members`;
//sql;
//        $this->execute($dropSql);
        $this->schema->dropIfExists($this->table);
    }
}
